package com.ncloud.resman.mapper;

import com.ncloud.resman.entity.ExportFire;

import com.ncloud.resman.entity.Firewall;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * Created by shiqiang on 2017/8/14.
 */
@Mapper
public interface FirewallMapper {
    @Insert("insert into res_device_base(device_id, sn_num, model_id, model_name, brand_id, brand_name, eqpt_type, eqpt_type," +
            " eqpt_spec, spec_name, state,create_user,create_date,update_user,update_date)"
            + " values(#{deviceId},#{snNum},#{modelId},#{modelName},#{brandId},#{brandName},#{eqptType},#{typeName}," +
            "#{eqptSpec},#{specName},#{state},#{createUser},#{createDate},#{updateUser},#{updateDate})")
    int insertFirewall(Firewall firewall);
    @Update("update res_device_base set sn_num = #{interfaceNum},model_id=#{modelId},model_name =#{modelName},brand_id =#{brandId}," +
            "brand_name =#{brandName},eqpt_type =#{eqptType},eqpt_type=#{typeName},eqpt_spec=#{eqptSpec},spec_name=#{specName}," +
            "state=#{state},update_user=#{updateUser},update_date=#{updateDate} where device_id =#{deviceId}")
    int updateFirewall(Firewall firewall);
    
  //通过SNNUM查询防火墙
    @Select("select a.device_id,a.model_name,a.sn_num,a.model_id,a.brand_id,a.brand_name,a.eqpt_spec,a.spec_name,"
    		+ "f_get_dict('eqpt_state',a.state) as state,b.room_id,b.room_name,b.cabinet_code,b.start_num,b.end_num,c.create_user from res_device_base a,res_device_location b,"
    		+ "res_device_server c where a.device_id=b.device_id and b.device_id=c.device_id and a.eqpt_type='4' and "
    		+ "if(#{0} is null,1=1,a.sn_num=#{0})")
    @Results({
		@Result(column="device_id",property="deviceId"),@Result(column="model_name",property="modelName"),
		@Result(column="sn_num",property="snNum"),@Result(column="model_id",property="modelId"),
		@Result(column="brand_id",property="brandId"),@Result(column="brand_name",property="brandName"),
		
		@Result(column="eqpt_spec",property="eqptSpec"),@Result(column="spec_name",property="specName"),
		@Result(column="state",property="state"),@Result(column="room_id",property="roomId"),
		@Result(column="room_name",property="roomName"),@Result(column="cabinet_code",property="cabinetCode"),
		
		@Result(column="start_num",property="startNum"),@Result(column="end_num",property="endNum"),
		@Result(column="create_user",property="createUser")})
    List<ExportFire> getFireInfoBySnNum(String snNum);
}
